<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" stretch v-model="currentTab">
      <el-tab-pane name="loginAccount">
        <template #label>
          <span>
            <el-icon class="icon"><UserFilled /></el-icon> 用户名登陆
          </span>
        </template>
        <LoginAccount ref="loginAccountRef" />
      </el-tab-pane>
      <el-tab-pane name="loginPhone">
        <template #label>
          <span>
            <el-icon class="icon"><Cellphone /></el-icon> 手机号登陆
          </span>
        </template>
        <LoginPhone ref="loginPhoneRef" />
      </el-tab-pane>
    </el-tabs>
    <div class="login-controller">
      <el-checkbox v-model="isRememberPwd">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="login-commit" @click="handleLoginClick">立即登陆</el-button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'
import { localCache } from '@/utils/cache'

// 记住密码
const isRememberPwd = ref(!!(localCache.getCache('account')?.name ?? ''))
// 登录类型
const currentTab = ref('loginAccount')

const loginAccountRef = ref<InstanceType<typeof LoginAccount>>()
const loginPhoneRef = ref<InstanceType<typeof LoginPhone>>()

const handleLoginClick = () => {
  if (currentTab.value === 'loginAccount') {
    loginAccountRef.value?.loginAction(isRememberPwd.value)
  } else {
    loginPhoneRef.value?.loginAction()
  }
}
</script>
<style scoped lang="less">
.login-panel {
  margin-bottom: 130px;
  width: 320px;

  .title {
    text-align: center;
    margin-bottom: 20px;
  }
  .login-controller {
    display: flex;
    margin-top: 5px;
    color: yellowgreen;
    justify-content: space-between;
  }
  .login-commit {
    margin-top: 10px;
    width: 100%;
  }

  .icon {
    position: relative;
    top: 2px;
  }
}
</style>
